/**
 * File: NodeCoverageStatistic.java
 * Created by: mhaimel
 * Created on: Mar 26, 2010
 * CVS:  $Id: NodeCoverageStatistic.java 1.0 Mar 26, 2010 5:14:46 PM mhaimel Exp $
 */
package uk.ac.ebi.curtain.model.graph.curtain.filter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import uk.ac.ebi.curtain.model.graph.Node;
import uk.ac.ebi.curtain.model.graph.GraphAccess.TouchEach;
import uk.ac.ebi.curtain.model.graph.curtain.ContigInfo;
import uk.ac.ebi.curtain.model.graph.curtain.ReadWrapper;
import uk.ac.ebi.curtain.model.graph.curtain.StatisticSummary;
import uk.ac.ebi.curtain.utils.StatisticHelper;

/**
 * @author mhaimel
 *
 */
public class NodeCoverageStatistic implements TouchEach<Node<ContigInfo, ReadWrapper>> {

	private final LinkedBlockingQueue<Integer> bpCov;
//	private final AtomicReferenceArray<LinkedBlockingQueue<Long>> bpLen;
	private final Integer category;

	public NodeCoverageStatistic(Integer category) {
		this.category = category;
		this.bpCov = new LinkedBlockingQueue<Integer>();
//		this.bpLen = new AtomicReferenceArray<LinkedBlockingQueue<Long>>(categories);
//		for(int i = 0; i < categories; ++i){
//			this.bpCov.set(i, new LinkedBlockingQueue<Integer>());
//			this.bpLen.set(i, new LinkedBlockingQueue<Long>());
//		}
	}

	@Override
	public void touch(Node<ContigInfo, ReadWrapper> node) {
		if(null == node){
			return;
		}
		int val = node.getValue().calculateSequenceCoverage(category).intValue();
		if(val > 0){
			this.bpCov.add(val);
		}
	}
	
	public BlockingQueue<Integer> getBpCov() {
		return bpCov;
	}
//	public AtomicReferenceArray<LinkedBlockingQueue<Long>> getBpLen() {
//		return tjhibpLen;
//	}
	
	public StatisticSummary<Integer> getStatistics() {
		List<Integer> sorted = new ArrayList<Integer>(this.bpCov);
		Collections.sort(sorted);
		return StatisticHelper.getStatistic(sorted);
	}
	
	public StatisticHelper<Integer> getStatisticHelper() {
		List<Integer> sorted = new ArrayList<Integer>(this.bpCov);
		Collections.sort(sorted);
		return new StatisticHelper<Integer>(sorted,true);
	}
	
}
